package config

import (
	"encoding/json"
	"fmt"
	"os"
	"strconv"
)

type WebSiteConfig struct {
	Port       int
	ServerAddr string
	URL        string
	SourceName string
}

func ReadConfig() {
	configFile, err := os.Open("./conf.json")
	if err != nil {
		fmt.Fprintln(RealStdout, err.Error())
		return
	}
	defer configFile.Close()
	decoder := json.NewDecoder(configFile)
	conf := WebSiteConfig{}
	err = decoder.Decode(&conf)
	if err != nil {
		fmt.Fprintln(RealStdout, err.Error())
		return
	}
	URL = conf.URL
	ServerAddr = conf.ServerAddr + ":" + strconv.FormatInt(int64(conf.Port), 10)
	Srv.Addr = ServerAddr
	SourceName = conf.SourceName
}
